import { createRouter, createWebHistory } from "vue-router";

// 从meta 中提取路径信息
const baseUrl =
  document.getElementsByTagName("meta").namedItem("spa-router-base")?.getAttribute("content") ||
  document.getElementsByTagName("base")[0]?.getAttribute("href") ||
  import.meta.env.BASE_URL;

const router = createRouter({
  // history: createWebHistory(import.meta.env.BASE_URL),
  history: createWebHistory(baseUrl),
  routes: [
    { path: "/", redirect: "/Home" },
    {
      path: "/Home",
      name: "Home",
      component: () => import("../views/HomeView.vue"),
    },
    {
      path: "/Login",
      name: "Login",
      component: () => import("../views/Login/MainView.vue"),
    },
    {
      path: "/Register",
      name: "Register",
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import("../views/RegisterView.vue"),
    },
    {
      path: "/ForgotPassword",
      name: "ForgotPassword",
      component: () => import("../views/ForgetPasswordView.vue"),
    },
  ],
});

export default router;
